package com.own.business.wechat.mobile.entity.vo;

import com.own.business.wechat.mobile.entity.po.WechatMobileAuthentication;
import com.own.component.common.base.entity.vo.BaseBeanVo;
import com.own.constant.ConstantBeanSuffix;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;

/**
 * WechatMobileAuthenticationVo
 *
 * @author chenxueli
 * @date 2023-06-30 09:06:33
 */
@Schema(title = "微信移动应用认证" + ConstantBeanSuffix.VO)
@Getter
@Setter
@ToString
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
public class WechatMobileAuthenticationVo extends BaseBeanVo<WechatMobileAuthentication> implements Serializable {

    @Schema(title = "验证code")
    private String code;

    @Schema(title = "接口调用凭证")
    private String accessToken;

    @Schema(title = "access_token 接口调用凭证超时时间，单位（秒）")
    private Integer expiresIn;

    @Schema(title = "用户刷新 access_token")
    private String refreshToken;

    @Schema(title = "授权用户唯一标识")
    private String openId;

    @Schema(title = "用户授权的作用域，使用逗号（,）分隔")
    private String scope;

    @Schema(title = "用户统一标识。针对一个微信开放平台帐号下的应用，同一用户的 unionid 是唯一的")
    private String unionId;

    /**
     * 构造方法
     *
     * @param entity 原对象
     */
    public WechatMobileAuthenticationVo(@NonNull WechatMobileAuthentication entity) {
        super(entity);
        this.code = entity.getCode();
        this.accessToken = entity.getAccessToken();
        this.expiresIn = entity.getExpiresIn();
        this.refreshToken = entity.getRefreshToken();
        this.openId = entity.getOpenId();
        this.scope = entity.getScope();
        this.unionId = entity.getUnionId();
    }

    /**
     * 转po对象
     *
     * @param entity 原对象
     * @return po对象
     */
    @Override
    public WechatMobileAuthentication toPo(WechatMobileAuthentication entity) {
        if (entity == null) {
            entity = new WechatMobileAuthentication();
        }
        entity.setCode(this.code);
        entity.setAccessToken(this.accessToken);
        entity.setExpiresIn(this.expiresIn);
        entity.setRefreshToken(this.refreshToken);
        entity.setOpenId(this.openId);
        entity.setScope(this.scope);
        entity.setUnionId(this.unionId);
        return super.toPo(entity);
    }

}
